﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 刘安超_插入排序
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] b = { 23, 3, 45, 90, 76, 49, 39 };
            Insertsort(b);
        }

        public static void Insertsort(int[] a)
        {
            int i, j;
            for ( i = 0; i < a.Length; i++)     // 外层循环，共(a.length-1)趟排序
            {                                   
                if (a[i] < a[i-1])              // 判断大小
                {
                    int temp = a[i];            // 当a[j]<=temp
                    for ( j = i-1; j >=0 && a[j]<temp; j--)
                    {
                        a[j+1] = a[j];
                    }
                    a[j+1] = temp;
                }
            }
        }
    } 
}
